package com.ext.aic.apis.user;

import com.ext.aic.apis.BaseUrlConfig;
import com.ext.aic.beans.response.PreUploadResponse;
import com.eyinfo.android_pure_utils.events.Func2;

import java.util.HashMap;

import io.github.eyinfo.okrx.BaseOkRxService;
import io.github.eyinfo.okrx.BaseSubscriber;
import io.github.eyinfo.okrx.annotations.APIUrlInterfaceClass;
import io.github.eyinfo.okrx.annotations.ApiCheckAnnotation;
import io.github.eyinfo.okrx.beans.RetrofitParams;
import io.github.eyinfo.okrx.enums.DataType;
import io.github.eyinfo.okrx.enums.ErrorType;
import io.github.eyinfo.okrx.events.OnSuccessfulListener;

@APIUrlInterfaceClass(BaseUrlConfig.class)
public class PreUpdateService extends BaseOkRxService {

    protected void onPreUpdateFail() {

    }

    protected void onPreUpdateSuccess(PreUploadResponse response) {

    }

    @ApiCheckAnnotation
    public void preUpload(String resourceName) {
        BaseSubscriber<PreUploadResponse, PreUpdateService> subscriber = new BaseSubscriber<>(this);
        subscriber.setOnSuccessfulListener(new OnSuccessfulListener<PreUploadResponse>() {
            @Override
            public void onSuccessful(PreUploadResponse response, DataType dataType, Object... extras) {
                onPreUpdateSuccess(response);
            }

            @Override
            public void onError(ErrorType errorType, Object... extras) {
                onPreUpdateFail();
            }
        });
        requestObject(IUpdateRequest.class, this, subscriber, new Func2<RetrofitParams, IUpdateRequest, HashMap<String, Object>>() {
            @Override
            public RetrofitParams call(IUpdateRequest updateRequest, HashMap<String, Object> stringObjectHashMap) {
                return updateRequest.preUpload(resourceName);
            }
        });
    }
}
